
#include "zos_config.h"
#ifdef BOARD_USING_TIMER_DEMO

#include "zos.h"

//定义软定时器句柄
zos_timer_t demo_timer1_handlr = ZOS_NULL;
zos_timer_t demo_timer2_handlr = ZOS_NULL;


//软定时1回调函数
void demo_timer1_cb(void *parameter)
{
    zos_printf("demo timer1 callback\r\n");
}

//软定时2回调函数
void demo_timer2_cb(void *parameter)
{
    zos_printf("demo timer2 callback\r\n");
}



int demo_timer_init(int argc, char *argv[])
{
    //创建软定时1，每次调用zos_timer_start()开启，只运行一次
    demo_timer1_handlr = zos_timer_create("demo_timer",demo_timer1_cb,ZOS_NULL,TIMER_FLAG_ONE_SHOT);
    
    //创建软定时1，调用zos_timer_start()开启以后循环运行，想要关闭需要调用zos_timer_stop()
    demo_timer2_handlr = zos_timer_create("demo_timer",demo_timer2_cb,ZOS_NULL,TIMER_FLAG_PERIODIC);

    //开启软定时1，定时周期为2000ms,只执行一次
    zos_timer_start(demo_timer1_handlr,2000);

    //开启软定时2，定时周期为1000ms，循环执行
    zos_timer_start(demo_timer2_handlr,1000);

    //等待3000ms
    zos_task_delay(3000);

    //关闭软定时2
    zos_timer_stop(demo_timer2_handlr);

    //等待5000ms
    zos_task_delay(5000);

    //重新开启软定时器2，定时周期为1000ms，循环执行
    zos_timer_start(demo_timer2_handlr,1000);
    //重新开启软定时器1，定时周期为1000ms，单次执行
    zos_timer_start(demo_timer1_handlr,1000);

    //等待5000ms
    zos_task_delay(5000);

    //删除软定时器2
    zos_timer_delete(demo_timer2_handlr);

    //删除软定时器1
    zos_timer_delete(demo_timer1_handlr);
    return	ZOS_EOK;
}


#include "shell.h"

SHELL_EXPORT_CMD(demo_timer,demo_timer_init, timer demo);

#endif

